(function(window, document) {
    angular
        .module('app')
        .controller('accountDetailController', accountDetailController);

    accountDetailController.$inject = [
        'accountDetailFactory',
        'uidFactory',
        '$stateParams'
    ];


    function accountDetailController(accountDetailFactory, uidFactory, $stateParams) {
        var vm = this;
        var uid = uidFactory.getUid() || 1;
        var dayid = $stateParams.accountdayid;

        // 设置获取帐号详细的所需参数
        accountDetailFactory.setUid(uid);
        accountDetailFactory.setDayid(dayid);

        accountDetailFactory.accountDetailPromise().then(accountDetailPromiseSuccess, accountDetailPromiseFail);

        /**
         * 获取帐号天数详细
         * @param  {object} data 后台接口返回值
         * @return null
         */
        function accountDetailPromiseSuccess (data) {
            switch(data.returncode) {
                case 0:
                    vm.accountDetail = data.list;
                    break;
                case -1:
                    alert('已购买同类型账号，到期后才能再次购买哦！');
                    history.go(-1);
                    break;
                case -999:
                    alert('系统维护升级中！');
                    break;
            }
        }

        /**
         * 获取帐号天数详细失败
         * @param  {object} err 错误返回值
         * @return null
         */
        function accountDetailPromiseFail (err) {
            alert(err);
        }

    }
})(window, document);
